package Code;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class Code128 {
    static int longestStr(int[] nums){
        Set<Integer> set = new HashSet<>();

        for(int num : nums){
            set.add(num);
        }
        int res = 0;
        for(int num : set){
            if(!set.contains(num-1)){
                int curLen = 1;
                int curNum = num;
                while(set.contains(curNum+1)){
                    curNum++;
                    curLen++;
                }
                res = Math.max(res, curLen);
            }

        }
        return res;
    }
    public static void main(String[] args) {
        System.out.println(longestStr(new int[]{1,0,1,2}));
    }
}
